package com.prs.crm.action.personalset;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.personalset.PersonalMessageGroup;
import com.prs.crm.service.personalSet.PersonalMessageGroupService;

public class PersonalMessageGroupAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private PaginationSupport pagination;
	private PersonalMessageGroup personalMessageGroup;
	private PersonalMessageGroupService personalMessageGroupService;
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}

	public PersonalMessageGroup getPersonalMessageGroup() {
		return personalMessageGroup;
	}
	public void setPersonalMessageGroup(PersonalMessageGroup personalMessageGroup) {
		this.personalMessageGroup = personalMessageGroup;
	}
	public PersonalMessageGroupService getPersonalMessageGroupService() {
		return personalMessageGroupService;
	}
	public void setPersonalMessageGroupService(
			PersonalMessageGroupService personalMessageGroupService) {
		this.personalMessageGroupService = personalMessageGroupService;
	}
	@Action("listPersonalMessageGroup")
	public String listPersonalMessageGroup(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(PersonalMessageGroup.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getPersonalMessageGroupService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	
	@Action("editPersonalMessageGroup")
	public String editPersonalMessageGroup(){
		if(ids!=null){
			this.personalMessageGroup=this.getPersonalMessageGroupService().get(ids[0]);
		}
		return SUCCESS;
	}
	
	@Action(value="savePersonalMessageGroup",results={
			@Result(name="success",type="redirect",location="listPersonalMessageGroup"),
			@Result(name="error",type="chain",location="editPersonalMessageGroup")
	})
	public String savePersonalMessageGroup(){
		this.getPersonalMessageGroupService().save(personalMessageGroup);
		return SUCCESS;
	}
	
	@Action(value="removePersonalMessageGroup",results={
			@Result(name="success",type="redirect",location="listPersonalMessageGroup"),
			@Result(name="error",type="chain",location="listPersonalMessageGroup")
	})
	public String removePersonalMessageGroup(){
		if(ids!=null){
			this.personalMessageGroup=this.getPersonalMessageGroupService().get(ids[0]);
		}
		this.getPersonalMessageGroupService().batchRemove(ids);
		return SUCCESS;
	}
}
